package com.exmaple.mapreducer.salarytotal;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//map阶段
public class SalaryTotalMapper extends Mapper<LongWritable, Text, IntWritable,IntWritable> {

    private  IntWritable k2 = new IntWritable();//部门编号作为k2
    private   IntWritable v2 = new IntWritable();//工资作为v2
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //1. v1由Text类型转换为String：toString()方法
          // 7369,SMITH,CLERK,7902,1980/12/17,800,,20
        String line = value.toString();
        //2. 按逗号进行分词：split(“,”)方法
        String[] datas = line.split(",");
        // 3. 取出需要的字段：部门号：字段[7]、工资：字段[5]
        String deptNo = datas[7]; //拿到部门编号
        k2.set(Integer.parseInt(deptNo));
        v2.set(Integer.parseInt(datas[5]));
        // 4. 输出k2, v2：context.write()方法
        context.write(k2,v2);


    }
}
